package com.zx.framework.core.util.layer;

import java.util.ArrayList;
import java.util.List;

import com.zx.framework.core.util.StringUtil;

/**
 * 描述拆分后的layer
 * @author administator
 *
 */
public class LayerModle{
	
	private String prefix;
	private String suffix;
	private List<String> group = new ArrayList<String>();
	private String max;
	
	public String getPrefix() {
		return prefix;
	}
	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}
	public String getSuffix() {
		return suffix;
	}
	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}
	public List<String> getGroup() {
		return group;
	}
	public void setGroup(List<String> group) {
		this.group = group;
	}
	public String getMax() {
		return max;
	}
	public void setMax(String max) {
		this.max = max;
	}
	
	/**
	 * 获取下一个增加的layer
	 * @param layer
	 * @return
	 */
	public String getNext(){
		if(this.group.isEmpty()){
			throw new RuntimeException("group must not  null!");
		}
		long s = Long.parseLong(LayerUtil.MAX, LayerUtil.RADIX);
		//取末尾3位
		long rs = Long.parseLong(group.get(group.size()-1), LayerUtil.RADIX);
		long l = rs +1;
		if(l>s){
			throw new RuntimeException("next layer beyond :"+ max);
		}
		String ls = Long.toString(l, LayerUtil.RADIX);
		if( LayerUtil.LENGTH != ls.length()){
			int zeroCnt = LayerUtil.LENGTH - ls.length();
			String temp = "";
			for (int i = 0; i < zeroCnt; i++) {
				temp+="0";
			}
			ls = temp+ls;
		}
		
		if(group.size()==1){
			if(StringUtil.isEmpty(prefix)){
				return ls;
			}
			else{
				return prefix +LayerUtil.SPLIT +ls;
			}
		}
		String result = "";
		for (int i = 0; i < group.size()-1; i++) {
			result += group.get(i);
		}
		
		return prefix+LayerUtil.SPLIT  + (result + ls).toUpperCase();
	}
}
